#input thread_id,and view its posts

import wsgiref.handlers

from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from BeautifulSoup import BeautifulSoup

import xmw
from xmw.db import ds
import simplejson
import logging
from xmw.db import user_mgr

class MainPage(xmw.RequestHandler):
    def get(self):
        (sub_req_id,e) = self.get_key_from_GET('sub_req_id')
        sub_req_id  =sub_req_id.strip().decode('utf-8')
        (option,e) = self.get_key_from_GET('option')
        option  =option.strip().decode('utf-8')
        #user =user_mgr.get_user_by_mail(email)
        q_sub_req=ds.Sub_Req.all()
        q_sub_req.filter('sub_req_id =', sub_req_id)
        sub = q_sub_req.get()
        sub.option=int(option)
        sub.put()
        
        data={'option':sub.option}
        data_js= simplejson.dumps(data)
        logging.log( logging.INFO, "set sub option:%s"% str(data_js))
        self.response.headers['Content-Type'] = 'application/json; charset=utf-8'
        self.response.out.write(data_js)
        #self.response.out
        
        return

def main():
    application = webapp.WSGIApplication(
                                       [('/j/subscribe/sub_option', MainPage)],
                                       debug=True)
    wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
  main()
